import axios from 'axios'


// create an axios instance
const service = axios.create({
    
    baseURL: "/api/", // api的base_url
    timeout: 50000 // request timeout
})

service.interceptors.request.use(config => {

    return config
}, error => {
    // Do something with request error
    console.log(error) // for debug
    Promise.reject(error)
})

// respone interceptor
service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            const res = response.data
            return res
        }
        if (response.status === 401) {
            
            return Promise.reject('401')
        }
        return Promise.reject('error')
    },
    error => {
        
        if (error.response.status === 401) {
         
        }
        return Promise.reject(error)
    })

export default service
